package com.situ.mall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.mall.common.exception.SituException;
import com.situ.mall.pojo.entity.user.User;
import com.situ.mall.user.mapper.UserMapper;
import com.situ.mall.user.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Z
 * @since 2024-10-14
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    private UserMapper userMapper;

    @Autowired
    public UserServiceImpl (UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User login(User user) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name", user.getName());
        User loginUser = userMapper.selectOne(queryWrapper);
        System.out.println("--------------------------");
        System.out.println(userMapper);
        if (loginUser == null) {
            throw new SituException("用户名不存在");
        }
        if (!user.getPassword().equalsIgnoreCase(loginUser.getPassword())) {
            throw new SituException("密码错误");
        }
        return loginUser;
    }
}
